<?php
$title = 'Attribution de boutiques au '.$marche->libelle;
$this->headTitle($title);
?>
<link href="<?php echo $this->basePath() . '/css/operationtest/multi-select.css'; ?>" media="screen" rel="stylesheet" type="text/css">
<script type="text/javascript">
    $(document).ready(function() {
        $('.selectable').multiSelect({
            selectableHeader: "<div class='custom-header'><input type='text' id='all-search' class='search-input' autocomplete='off' placeholder='Rechercher'><a onclick=\"multiSelectAll('select_all')\" class='ms-all'>Tout</a></div>",
            selectionHeader: "<div class='custom-header'><input type='text' id='my-search' class='search-input' autocomplete='off' placeholder='Rechercher'><a  onclick=\"multiSelectAll('deselect_all')\" class='ms-all'>Aucun</a></div>",
            selectableFooter: "<div class='custom-footer'><b>Boutiques disponibles</b></div>",
            selectionFooter: "<div class='custom-footer'><b>Boutiques choisies</b></div>"
        });
        
        $('#all-search').bind('keydown keypress keyup change', function(e) {
            if (e.which == 13 || e.keyCode == 13) {
                return false;
            } else {
                var search = this.value;
                var $li = $(".ms-selectable .ms-elem-selectable:not(.ms-selected)").hide();
                $li.filter(function() {
                    return $(this).text().toLowerCase().indexOf(search.toLowerCase()) >= 0;
                }).show();
            }
        });
        
        $('#my-search').bind('keydown keypress keyup change', function(e) {
            if (e.which == 13 || e.keyCode == 13) {
                return false;
            } else {
                var search = this.value;
                var $li = $(".ms-selection .ms-elem-selection.ms-selected").hide();
                $li.filter(function() {
                    return $(this).text().toLowerCase().indexOf(search.toLowerCase()) >= 0;
                }).show();
            }
        });
    });
</script>
<div class="content-head">
    <h3><?php echo $title; ?></h3>
    <div class="toolbar">        
        <button id="reset-btn" class="btn pull-right" onClick="otherCancel('marche')">Annuler</button>
    </div>
</div>

<div class="content-body">
    <form method="post">
        <select multiple="multiple" class="selectable" name="selectable[]">
            <?php foreach($allstores as $store){ 
                $selected = (in_array($store->idStore, $myallstores))?"selected":""; var_dump($selected); ?>
            <option value="<?php echo $store->idStore; ?>" <?php echo $selected; ?>><?php echo ucwords(strtolower($store->name)); ?></option>
             <?php } ?>
        </select>
        <p style="margin:20px 0; text-align:center"><input class="button" type="submit" name="submit" value="Enregistrer" /></p>
    </form>
    <script src="<?php echo $this->basePath() . '/js/operationtest/jquery.quicksearch.js'; ?>" type="text/javascript"></script>
    <script src="<?php echo $this->basePath() . '/js/operationtest/jquery.multi-select.js'; ?>" type="text/javascript"></script>
</div>